using System;
using UnityEditor;
using UnityEngine;

namespace Game.Expand
{
    public class CopyGameObjectPath
    {
        [MenuItem("GameObject/复制层级路径", false, 0)]
        static public void CopyPath(MenuCommand menuCommand)
        {
            var path = Selection.activeGameObject.name;
            var parent = Selection.activeGameObject.transform.parent;
            while (parent != null)
            {
                if (parent.name.Equals("Canvas (Environment)"))
                {
                    parent = null;
                }
                else
                {
                    path = parent.name + "/" + path;
                    parent = parent.parent;
                }
            }

            var firstIndex = path.IndexOf("/", StringComparison.Ordinal);
            path = path.Substring(firstIndex + 1, path.Length - firstIndex - 1);
            GUIUtility.systemCopyBuffer = path;
        }
    }
}

